package cn.fuxi2022.module.banner.controller;


import cn.fuxi2022.model.empty.applets.GroupBanner;
import cn.fuxi2022.model.resp.PageUtils;
import cn.fuxi2022.model.resp.R;
import cn.fuxi2022.module.banner.service.GroupBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 * 小程序首页轮播图表 前端控制器
 * </p>
 *
 * @author fuxi
 * @since 2022-10-15 11:06:59
 */
@RestController
@RequestMapping("/admin/banner")
public class GroupBannerController {
    @Autowired
    private GroupBannerService groupBannerService;


    /**
     * 列表
     */
    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> params) {
        PageUtils page = groupBannerService.queryPage(params);

        return R.ok().data(page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
        GroupBanner groupBanner = groupBannerService.getById(id);

        return R.ok().data("groupBanner", groupBanner);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody @Validated(GroupBanner.Save.class) GroupBanner groupBanner) {
        groupBannerService.save(groupBanner);

        return R.ok("保存联系成功");
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody @Validated(GroupBanner.Update.class) GroupBanner groupBanner) {
        groupBannerService.updateById(groupBanner);

        return R.ok("修改联系成功");
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody String[] ids) {
        groupBannerService.removeByIds(Arrays.asList(ids));

        return R.ok("删除联系成功");
    }
}
